#include "VSAnimAtom.h"
#include "VSOtherMath.h"
#include "VSTransform.h"
using namespace VSEngine2;
void VSAnimAtom::Identity()
{
	m_fScale.Set(1.0f,1.0f,1.0f);
	m_Pos.Set(0.0f,0.0f,0.0f);
	m_Rotator.Set(0.0f,0.0f,0.0f,1.0f);

}
void VSAnimAtom::GetMatrix(VSMatrix3X3W & OutMatrix)
{
	VSMatrix3X3 mRotate;
	m_Rotator.GetMatrix(mRotate);

	VSMatrix3X3 Mat;
	Mat = VSMatrix3X3(	mRotate._00 * m_fScale.x,mRotate._01 * m_fScale.x,mRotate._02 * m_fScale.x,
						mRotate._10 * m_fScale.y,mRotate._11 * m_fScale.y,mRotate._12 * m_fScale.y,
						mRotate._20 * m_fScale.z,mRotate._21 * m_fScale.z,mRotate._22 * m_fScale.z);
	OutMatrix.AddTranslate(m_Pos);
	OutMatrix.Add3X3(Mat);
}
void VSAnimAtom::Interpolation(const VSAnimAtom & Atom1 , const VSAnimAtom Atom2,VSREAL t)
{
	while (t < 0.0f)
	{
		t += 1.0f;
	}
	while(t > 1.0f)
	{
		t -= 1.0f;
	}

	m_fScale = LineInterpolation(Atom1.m_fScale,Atom2.m_fScale,t);
	m_Pos = LineInterpolation(Atom1.m_Pos,Atom2.m_Pos,t);
#ifdef USE_ROTATOR_LINE_INTERPOLATION
	m_Rotator.Slerp(t,Atom1.m_Rotator,Atom2.m_Rotator);
#else
	m_Rotator = LineInterpolation(Atom1.m_Rotator,Atom2.m_Rotator,t);
#endif
	


}

void    VSAnimAtom::operator *= (VSREAL f)
{
	m_fScale *= f;
	m_Pos *= f;
#ifdef USE_ROTATOR_LINE_INTERPOLATION
	m_Rotator = m_Rotator.Pow(f);
#else
	m_Rotator *= f;
#endif
}
VSAnimAtom VSAnimAtom::operator *  (VSREAL f)
{
	VSAnimAtom Temp ;
	Temp.m_fScale = m_fScale * f;
	Temp.m_Pos = m_Pos * f;
#ifdef USE_ROTATOR_LINE_INTERPOLATION
	Temp.m_Rotator = m_Rotator.Pow(f);
#else
	Temp.m_Rotator = m_Rotator * f;
#endif
	return Temp;

}
void VSAnimAtom::operator += (const VSAnimAtom &Atom)
{
	m_fScale += Atom.m_fScale;
	m_Pos += Atom.m_Pos;
#ifdef USE_ROTATOR_LINE_INTERPOLATION
	m_Rotator *= Atom.m_Rotator;
#else
	m_Rotator += Atom.m_Rotator;
#endif
}
VSAnimAtom VSAnimAtom::operator +  (const VSAnimAtom &Atom) const
{
	VSAnimAtom Temp ;
	Temp.m_fScale = m_fScale + Atom.m_fScale;
	Temp.m_Pos = m_Pos + Atom.m_Pos;
#ifdef USE_ROTATOR_LINE_INTERPOLATION
	Temp.m_Rotator = m_Rotator * Atom.m_Rotator;
#else
	Temp.m_Rotator = m_Rotator + Atom.m_Rotator;
#endif
	return Temp;
}